package com.karst.essentials.chapter10
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	import org.papervision3d.core.geom.renderables.Particle;
	import org.papervision3d.materials.special.BitmapParticleMaterial;

	internal class BitmapParticleMaterialImageExample extends ParticleTemplate
	{
		public function BitmapParticleMaterialImageExample()
		{
			super();
		}
		
		override protected function createView():void
		{
			super.createView() ;
			
			var imgLoader : Loader = new Loader() ;
			imgLoader.contentLoaderInfo.addEventListener( Event.COMPLETE, loadedImgHandler ) ;
			imgLoader.load( new URLRequest( "http://bbs.9ria.com/images/forumicons/iCube.gif" ) ) ;
		}
		
		private function loadedImgHandler( $event : Event ) : void
		{
			var bmp : Bitmap = $event.target.content as Bitmap ;
			var material : BitmapParticleMaterial = new BitmapParticleMaterial( bmp.bitmapData ) ;
			material.smooth = true ;
			
			for( var i : int = 0 ; i < numOfPartices; i++)
			{
				var particle : Particle = new Particle( material, 1,
					randPos(), randPos(), randPos() ) ;
				particles.addParticle( particle ) ;
			}
		}
	}
}